package cn.jbolt.admin.hiprint;

import cn.jbolt.core.api.JBoltApiBaseController;
import cn.jbolt.core.api.JBoltBaseController;
import cn.jbolt.core.model.GlobalConfig;
import cn.jbolt.core.model.HiprintTpl;
import cn.jbolt.core.permission.CheckPermission;
import cn.jbolt.core.permission.OnlySaasPlatform;
import cn.jbolt.core.permission.UnCheck;
import cn.jbolt.core.permission.UnCheckIfSystemAdmin;
import cn.jbolt.extend.permission.PermissionKey;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Inject;
import com.jfinal.core.ActionKey;
import com.jfinal.core.Path;
import com.jfinal.core.paragetter.Para;

/**
 * jbolt hiprint 封装
 * @ClassName:  HiprintAdminController
 * @author: JFinal学院-小木 QQ：909854136 
 * @date:   2021年8月28日   
 *    
 */
@CheckPermission(PermissionKey.HIPRINT_DESIGN)
@UnCheckIfSystemAdmin
@OnlySaasPlatform
@Path("/api/admin/hiprint")
public class HiprintAdminController extends JBoltApiBaseController {
	@Inject
	private HiprintTplService tplService;


	/**
	 * 模板获取
	 */
	@UnCheck
	@ActionKey("tpl/content")
	public void tplContent() {
		HiprintTpl tpl = tplService.getCacheByKey(get("sn"));
		if(tpl == null) {
			renderJBoltApiFail("hiprint打印模板加载失败");
		}else {
			renderJBoltApiSuccessWithData(tpl.getContent());
		}
	}
	/**
	 * 模板库数据
	 */
	@ActionKey("tpl/datas")
	public void tplDatas() {
		renderJBoltApiSuccessWithData(tplService.paginateAdminDatas(getPageNumber(),getPageSize(),getKeywords(),getEnable(),"content"));
	}
	/**
	 * 模板库数据加载一个
	 */
	@ActionKey("tpl/load")
	public void tplLoad() {
		renderJBoltApiSuccessWithData(tplService.findByIdLoadColumns(getLong(0), "id","name","content"));
	}
	/**
	 * 模板库数据加载一个
	 */
	@ActionKey("tpl/testJsonData")
	public void tplTestJsonData() {
		JSONObject json = new JSONObject();
		json.put("title", "JBolt极速开发平台");
		json.put("qrcode", "http://jbolt.cn/jbolt.html");
		json.put("barcode", "123456789");
		json.put("avatar", "assets/img/avatar.png");
		json.put("imgurl", "assets/img/jfinalxylogo.png");
		renderJBoltApiSuccessWithData(json);
	}
	
	/**
	 * 提交模板
	 */
	@ActionKey("tpl/submit")
	public void submitTpl(@Para("") HiprintTpl tpl) {
		renderJBoltApiRet(tplService.submitTpl(tpl));
	}
	/**
	 * 删除模板
	 */
	@ActionKey("tpl/delete")
	public void tplDelete() {
		renderJBoltApiRet(tplService.deleteById(getLong(0)));
	}
}
